using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Pabo.Calendar;

namespace EIM_Accounting
{
    /// <summary>
    /// 节假日设定
    /// </summary>
    public partial class CM010104 : Form
    {
        public DateTime inMonth;
        public List<int> staffIDList;
        private BLL.CM010104 cm010103;

        public CM010104()
        {
            InitializeComponent();

            cm010103 = new BLL.CM010104();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                SelectedDatesCollection selectDates = monthCalendar1.SelectedDates;
                List<Accounting.Model.Holiday> lstHoliday = new List<Accounting.Model.Holiday>();
                List<string[]> staffMonth = new List<string[]>();
                foreach (int staffId in staffIDList)
                {
                    foreach (DateTime ddd in selectDates)
                    {
                        Accounting.Model.Holiday holidayModel = new Accounting.Model.Holiday();
                        holidayModel.StaffID = staffId;
                        holidayModel.HolidayDate = ddd.ToString("yyyyMMdd");

                        lstHoliday.Add(holidayModel);
                    }
                    string[] dstemp = new string[2];
                    dstemp[0] = staffId.ToString();
                    dstemp[1] = new DateTime(monthCalendar1.ActiveMonth.Year, monthCalendar1.ActiveMonth.Month, 1).ToString("yyyyMM");
                    staffMonth.Add(dstemp);
                }

                cm010103.addBatch(lstHoliday, staffMonth);
                this.Close();
            }
            catch (Exception EX)
            {
                MessageBox.Show(EX.Message);
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void CM010104_Load(object sender, EventArgs e)
        {
            if (staffIDList == null || staffIDList.Count < 1)
            {
                this.Close();
            }

            if (inMonth.Year > 2000)
            {
                monthCalendar1.ActiveMonth.Year = inMonth.Year;
                monthCalendar1.ActiveMonth.Month = inMonth.Month;
            }
            if (staffIDList.Count == 1 && inMonth.Year > 2000)
            {
                List<DateTime> selectDate = cm010103.getSelectDate(inMonth.ToString("yyyyMM"), staffIDList[0].ToString());

                int i = 0;
                DateItem[] array = new DateItem[selectDate.Count];
                foreach (DateTime sd in selectDate)
                {
                    array[i] = new DateItem();
                    array[i].Date = sd;
                    array[i].BackColor1 = Color.LightSeaGreen;
                    i++;
                }
                monthCalendar1.SelectedDates.AddRange(selectDate.ToArray());
                //this.monthCalendar1.AddDateInfo(array);
            }
        }
    }
}